/**
 * $Id: UserLogoutSuccessHandler.java 45 2011-10-06 09:42:07Z feigme@gmail.com $
 */
package com.iary.interfaces.security;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;

public class UserLogoutSuccessHandler implements LogoutSuccessHandler {

	private String adminSignOutUrl;
	private String onlineSingOutUrl;

	public void onLogoutSuccess(HttpServletRequest request,
			HttpServletResponse response, Authentication authentication)
			throws IOException, ServletException {
		String targetUrl;
		String type = (String) request.getSession().getAttribute("type");
		if (type != null && type.equals("admin")) {
			targetUrl = adminSignOutUrl;
		} else {
			targetUrl = onlineSingOutUrl;
		}
		response.sendRedirect(request.getContextPath() + targetUrl);
	}

	public String getAdminSignOutUrl() {
		return adminSignOutUrl;
	}

	public void setAdminSignOutUrl(String adminSignOutUrl) {
		this.adminSignOutUrl = adminSignOutUrl;
	}

	public String getOnlineSingOutUrl() {
		return onlineSingOutUrl;
	}

	public void setOnlineSingOutUrl(String onlineSingOutUrl) {
		this.onlineSingOutUrl = onlineSingOutUrl;
	}

}
